<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var templateStr = '<h1>我买了一个{{thing}}，好{{mood}}的啊</h1>'
    var data = {
      thing: 'xiaomi',
      mood: 'happy'
    }
    console.log(templateStr.replace(/\{\{(\w+)\}\}/g, function (a, b, c, d) {
      console.log(a, b, c, d)
      return '*'
    }))
  </script>
</body>

</html>